<template>
	<view class="mainpadding">
		<view class="flexbetween">
			<view class="flexleft" @click="messageTime.timeShow = true" v-if="flag">
				<view class="ershiba nofonweight xiaohei">{{searchtime}}</view>
				<u-icon name="arrow-down"></u-icon>
			</view>
			<view class="flexright">
				<view class=" margin_right6">
					<view :class="current==0?'focustext':'nofocustext'" @click="selectab(0)">全部</view>
				</view>
				<view class=" margin_right6">
					<view :class="current==1?'focustext':'nofocustext'" @click="selectab(1)">收入</view>
				</view>
				<view class="">
					<view :class="current==2?'focustext':'nofocustext'" @click="selectab(2)">兑换</view>
				</view>
			</view>
		</view>
		<view class="flexleft margin_top2">
			<view class="strongtext nofonweight xiaohui margin_right3">收入：+{{dataAll.get_score}}</view>
			<view class="strongtext nofonweight xiaohui">兑换：{{dataAll.out_score}}</view>
		</view>
		<view class="flexcenter" v-if="!list.data.length">
			<view class="placeholderimage" style="margin-top: 300rpx;" ></view>
		</view>
		<view class="margin_top xiahuaxian flexbetween" v-for="item in list.data" :key="item.id">
			<view class="">
				<view class="ershiba nofonweight xiaohui">{{item.memo}}</view>
				<view class="strongtext nofonweight xiaohui margin_top2">{{item.createtime_text}}</view>
			</view>
			<view class="sanshier fonweight xiaohei">{{item.score}}</view>
		</view>
		<timePicker :messageTime="messageTime" @timeConfirm="timeConfirm"></timePicker>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				current: 0,
				messageTime: {
					timeShow: false,
					title: "选择筛选年月",
					mode: "year-month" //date日期，datetime年月日时分秒，time时间,year-month年月
				},
				flag:true,
				page: 1,
				limit: 12,
				list: {
					data: []
				},
				dataAll:{}
			}
			
		},
		onLoad() {
			this.searchtime = this.benyue()
		},
		onShow() {
			this.init()
			this.getjfmsg()
		},
		methods: {
			getjfmsg() {
				httpRequest.request('/api/user/getUserScoreLogData', 'GET', {
					searchtime:this.searchtime
				}).then(res => {
					this.dataAll = res.data
				})
			},
			init(isPage, page) {
				let _this = this;
				let url = "/api/user/getUserScoreLog"
				httpRequest.request(url, 'GET', {
					page: page || 1,
					limit: _this.limit,
					searchtime: this.searchtime,
					type:this.current
				}, false, false, true).then(res => {
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							_this.list = res.data
							_this.list.data = resList.data;
						}
					}
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
			benyue() {
				let y = new Date().getFullYear(); //获取年份
				let m = new Date().getMonth() + 1; //获取月份
				let d = '01'
				m = m < 10 ? '0' + m : m; //月份补 0
				return [y, m].join("-")
			},
			timeConfirm(e) {
				this.searchtime = e
				this.flag = false
				this.flag = true
				this.init()
				this.getjfmsg()
			},
			selectab(i) {
				if (i == this.current) {
					return false
				}
				this.current = i
				this.init()
			},
		}
	}
</script>

<style lang="scss" scoped>
	.focustext {
		font-size: 28rpx;
		font-family: PingFang SC-Bold, PingFang SC;
		font-weight: bold;
		color: #1BA95B;
	}

	.nofocustext {
		font-size: 28rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #000000;
	}
</style>